﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using TN_CMS.Admin.Helper.Common;
using TN_CMS.Domain.Entities;

namespace TN_CMS.Admin.Controllers
{
    public class TNController : Controller
    {
        public SysAdminShortInfoEntity SysAdmin
        {
            get
            {
                if (Session["TNController_SysAdmin"] != null)
                {
                    return (SysAdminShortInfoEntity)Session["TNController_SysAdmin"];
                }
                else
                {
                    return null;
                }
            }
            set
            {
                Session["TNController_SysAdmin"] = value;
            }
        }

        //make sure ExecuteCore will fired, change in MVC4 to support asynchronous action method => wil should change it latter
        protected override bool DisableAsyncSupport 
        {
            get
            {
                return true;
            }
        }

        protected override void ExecuteCore()
        {
            string cultureName = null;
            // Attempt to read the culture cookie from Request
            HttpCookie cultureCookie = Request.Cookies["_culture"];
            if (cultureCookie != null)
                cultureName = cultureCookie.Value;
            else
                cultureName = Request.UserLanguages[0]; // obtain it from HTTP header AcceptLanguages

            // Validate culture name
            cultureName = CultureHelper.GetImplementedCulture(cultureName); // This is safe


            // Modify current thread's cultures            
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName);
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

            base.ExecuteCore();
        }
    }
}
